﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Entity;
using NLBS.Framework;

namespace NLBS.Data.Business
{
    /// <summary>
    /// 用于留言缓存操作
    /// </summary>
   public class GuestBookData:CommonBase
    {
        #region GuestBook
        private static readonly string GuestBookPageKey = "GuestBook";
        public static List<GuestBook> GetPageGuestBook()
        {
            ContentCache cache=ContentCache.Instantiate();
            List<GuestBook> lists = (List<GuestBook>)cache[GuestBookPageKey];
            if (lists == null)
            {
                lists =new List<GuestBook>(DbProvider.Instance().GetGuestBook());
                if (lists != null)
                {
                    cache.Insert(GuestBookPageKey, lists, CacheDuration.Long);
                }
            }

            return lists;
        }

        public static List<GuestBook> GuestBookList
        {
            get
            {
                return GetPageGuestBook();
            }
        }

        public static GuestBook GetGuestBookByID(int id)
        {
            return GuestBookList.Find(delegate(GuestBook g)
            {
                return g.GuestBookID == id;
            });
        }

        public static void UpdateGuestBookByID(GuestBook gbook)
        {
            DbProvider.Instance().UpdateGuestBook(gbook);
        }
   

        public static void InsertGuestBook(GuestBook gbook)
        {
            DbProvider.Instance().InsertGuestBook(gbook);
            GuestBookList.Insert(0, gbook);
        }
        public static void DeleteGuestBook(int id)
        {
            DbProvider.Instance().DeleteGuestBook(id);
            GuestBookList.Remove(GetGuestBookByID(id));
        }

        #endregion
    }
}
